package com.yaosheng.thread.map;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CountDownLatch;

/**
 * Created by yaosheng on 2021/7/5.
 */
public class TestConcurrentHashMap {

    public static void main(String[] args) {

        Map<String,String> map = new ConcurrentHashMap<> ();
        //Map<String,String> map = new ConcurrentSkipListMap<> ();   //高并发并且排序

        Random r = new Random ();
        Thread[] t = new Thread[100];
        CountDownLatch latch = new CountDownLatch (t.length);
        long start = System.currentTimeMillis ();
        for(int i = 0;i < t.length;i ++){
            for(int j = 0;i < 10000;j ++) map.put ("a" + r.nextInt (100000),"a" + r.nextInt (100000));
            latch.countDown ();
        }

        Arrays.asList (t).forEach (ts -> ts.start ());
        try{
            latch.await ();
        } catch (InterruptedException e) {
            e.printStackTrace ();
        }
    }
}
